﻿@model Xms.Web.Models.PrivilegeModel
@{
    Layout = null;
}
@{
    DialogModel dialogModel = ViewData["DialogModel"] as DialogModel;
}

<!--（Modal） -->
<div class="modal fade" id="actionsModal" tabindex="-1" role="dialog"
     aria-labelledby="actionsModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">
                    ×
                </button>
                <h4 class="modal-title" id="actionsModalLabel">
                    <span class="glyphicon glyphicon-th"></span> @app.T["security_action_select_title"]
                </h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    @using (Html.BeginForm("SelectActionsDialog", "tool", FormMethod.Get, new { @id = "searchForm", @class = "form-horizontal", @role = "form" }))
                    {
                        @Html.Hidden("CallBack", dialogModel.CallBack)
                        @Html.Hidden("SingleMode", dialogModel.SingleMode)
                        <div class="form-group col-sm-12" style="height:30px;margin-bottom:0px;">

                            <label class="col-sm-2 control-label" for="clientip">@app.T["security_controller"]</label>
                            <div class="col-sm-10">
                                <div class="input-group">
                                    @Html.TextBoxFor(x => x.ClassName, new { @class = "form-control input-sm" })
                                    <span class="input-group-btn">
                                        <button class="btn btn-default btn-sm" type="submit">
                                            <span class="glyphicon glyphicon-search"></span> @app.T["search"]
                                        </button>
                                    </span>
                                </div>
                            </div>
                        </div>
                    }
                </div>
                <div class="table-responsive" id="gridview">

                    <table class="table table-striped table-hover table-condensed" id="datatable" data-ajax="true" data-ajaxcontainer="gridview" data-ajaxcallback="ajaxgrid_reset()" data-sortby="@Model.SortBy.ToLower()" data-sortdirection="@Model.SortDirection" data-singlemode="@dialogModel.SingleMode">
                        <thead>
                            <tr>
                                <th width="2%"><input type="checkbox" name="checkall" /></th>
                                <th data-name="ClassName">
                                    @app.T["security_controller"]
                                </th>
                                <th data-name="MethodName">
                                    @app.T["security_action"]
                                </th>
                                <th data-name="DisplayName">
                                    @app.T["description"]
                                </th>
                                <th width="2%">
                                    @app.T["operation_select"]
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var item in Model.Items)
                            {
                                <tr>
                                    <td><input type="checkbox" value="@item.MethodName" name="recordid" /></td>
                                    <td data-name="ClassName">@item.ClassName</td>
                                    <td data-name="MethodName">@item.MethodName</td>
                                    <td data-name="DisplayName">@item.DisplayName</td>
                                    <td>
                                        <a class="btn btn-link btn-xs" onclick="Xms.Web.SelectingRow(this);ActionsModel.dialog_return();"><span class="glyphicon glyphicon-ok"></span></a>
                                    </td>
                                </tr>
                            }
                        </tbody>
                    </table>
                    <div class="panel-footer">
                        <div class="row">
                            <div class="col-sm-4">
                                @(app.T["pagination_label"].Replace("{page}", Model.Page.ToString()).Replace("{totalpages}", Model.TotalPages.ToString()).Replace("{totalitems}", Model.TotalItems.ToString()))
                            </div>
                            <div id="page-selection" class="col-sm-8" data-total="@Model.TotalPages" data-page="@Model.Page"></div>
                        </div>
                    </div>
                    <script src="/content/js/jquery.bootpag.min.js?v=@app.PlatformSettings.VersionNumber"></script>
                    <script src="/content/js/jquery.form.js?v=@app.PlatformSettings.VersionNumber"></script>
                    <script>
                        var ActionsModel = {
                            pageUrl : '@app.Url',
                            callback : @dialogModel.CallBack,
                            dialog : $('#actionsModal'),
                            ajaxgrid_reset : function () {
                                ActionsModel.pag_init();
                                Xms.Web.DataTable($("#datatable"));
                            },
                            pag_init : function () {
                                $('#page-selection').bootpag({
                                    total: $('#page-selection').attr('data-total')
                                    , maxVisible: 5
                                    , page: $('#page-selection').attr('data-page')
                                    , leaps: false
                                    , prev: '&lsaquo;'
                                    , next: '&rsaquo;'
                                    , firstLastUse: true
                                    , first: '&laquo;'
                                    , last: '&raquo;'
                                }).on("page", function (event, /* page number here */ num) {
                                    event.preventDefault();
                                    var url = $.setUrlParam(ActionsModel.pageUrl, 'page', num);
                                    $("#gridview").ajaxLoad(url, "#gridview", function (response) {
                                        ActionsModel.ajaxgrid_reset();
                                    });
                                    return false;
                                });
                            },
                            dialog_return : function () {
                                var result = new Array();
                                $("#datatable").find("input[name=recordid]:checked").each(function (i, n) {
                                    var obj = new Object();
                                    obj.id = $(n).val();
                                    obj.classname = $(n).parent().siblings('[data-name=ClassName]').text();
                                    obj.methodname = $(n).parent().siblings('[data-name=MethodName]').text();
                                    obj.displayname = $(n).parent().siblings('[data-name=DisplayName]').text();
                                    result.push(obj);
                                });
                                var dialog = $(ActionsModel.dialogid);
                                if (dialog.data().OpenDialogCallback) {
                                    dialog.data().OpenDialogCallback(result, ActionsModel.inputid,ActionsModel)
                                } else {
                                    ActionsModel.callback && ActionsModel.callback(result,ActionsModel.inputid);
                                }
                                ActionsModel.dialog.modal('hide');
                                //Xms.Web.CloseDialog('#actionsModal');
                            }
                        };

                        $(function () {
                            ActionsModel.ajaxgrid_reset();
                            $('#searchForm').ajaxSearch('#gridview', ActionsModel.ajaxgrid_reset);
                            $("#datatable").ajaxTable();
                            ActionsModel.dialog.modal({
                                backdrop:'static'
                            });
                            ActionsModel.dialog.on('hidden.bs.modal', function () {
                                Xms.Web.CloseDialog('#actionsModal');
                            });
                        });
                    </script>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">
                    <span class="glyphicon glyphicon-remove"></span>
                    @app.T["dialog_close"]
                </button>
                <button type="button" class="btn btn-primary" onclick="ActionsModel.dialog_return()">
                    <span class="glyphicon glyphicon-ok"></span>
                    @app.T["dialog_ok"]
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div><!-- /.modal -->